from django.conf import settings
from itsdangerous import URLSafeTimedSerializer as Serializer


def generate_verify_email_url(user_id):
    """生成验证邮箱的链接地址"""
    # 1. 创建加密对象
    s = Serializer(secret_key=settings.SECRET_KEY, salt='email_verify')
    # 2. 构建加密数据
    data = s.dumps({'user_id': user_id})
    return data
   
def check_verify_token(token):
    s = Serializer(secret_key=settings.SECRET_KEY, salt='email_verify')
    try:
        result = s.loads(token)
    except Exception as e:
        return None
    else:
        return result.get('user_id')
